home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
PROBLEMS
/
BENCHMARK
/
BUBBLESORT
/
bubbletest
/
tile-forth
/
source
< prev
next >
Wrap
Text File
|
1992-05-17
|
1KB
|
51 lines
\ A classical benchmark of an O(n**2) algorithm; Bubble sort
\
\ Part of the programs gathered by John Hennessy for the MIPS
\ RISC project at Stanford. Translated to forth by Marty Fraeman
\ Johns Hopkins University/Applied Physics Laboratory.
\
\ a little bit modified for bubblesort benchmark test on acorn archimedes
os
string
variable pseudorandom ( -- addr)
: initiate-pseudorandom ( -- ) 123456 pseudorandom ! ;
: random ( -- n ) pseudorandom @ 234567 + 567 mod 345 + dup pseudorandom ! ;
1000 constant elements ( -- int)
align create list elements cells allot
: initiate-list ( -- )
list elements cells + list do random i ! cell +loop
;
: dump-list ( -- )
list elements cells + list do i @ . cell cr +loop
;
: bubble-with-flag ( -- )
1 elements 1 do
true list elements i - cells bounds do
i 2@ < if i 2@ swap i 2! drop false then
cell +loop
if leave then
loop
;
: start ( -- )
initiate-pseudorandom
initiate-list
dump-list
" time " oscli
bubble-with-flag
" time " oscli
dump-list
;
start
bye
bye